﻿@page
@model OpenPms.Areas.M.Pages.Setup.Rate.EditPriceDetailModel
@{
    var isDelay = Model.IsDelayPrice;
    ViewBag.Title = Model.RateType + "-" + Model.RateName + "-" + (isDelay ? "超时房价" : "房价");
    var weeks = "日一二三四五六";
}

<div class="weui-cells" style="display:none" id="DivShow">
    <div class="weui-cell" onclick="ShowTop()">
        <div class="weui-cell__bd">
            显示
        </div>
        <div class="weui-cell__ft"></div>
    </div>
</div>
<form method="post" id="FormPost">
    <div asp-validation-summary="ModelOnly"></div>
    <div id="DivTop">
        <div class="weui-cells weui-cells_form">
            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label" data-bs-toggle="tooltip" data-bs-title="包含当天">有效期</label></div>
                <div class="weui-cell__bd">
                    @if (isDelay)
                    {
                        <input readonly="readonly" class="weui-input" type="date" asp-for="Item.Date" asp-format="{0:yyyy-MM-dd}" />
                    }
                    else
                    {
                        <input class="weui-input" type="date" asp-for="Item.Date" asp-format="{0:yyyy-MM-dd}" />
                    }
                </div>
            </div>
        </div>
        <div class="weui-grids weui-cells weui-cells_checkbox">

            <div class="weui-grid" style="padding:0">
                <div class="weui-cell" onclick="CheckWeek(0)">
                    <div class="weui-cell__bd">
                        反选
                    </div>
                    <div class="weui-cell__ft"></div>
                </div>

            </div>
            <div class="weui-grid" style="padding:0">
                <div class="weui-cell" onclick="CheckWeek(1)">
                    <div class="weui-cell__bd">
                        全选
                    </div>
                    <div class="weui-cell__ft"></div>
                </div>
            </div>

            @for (int i = 0; i < 7; i++)
            {
                var id = "CB" + i;
                <div class="weui-grid" style="padding:0">
                    <label class="weui-cell weui-check__label" for="@id" data="@i">
                        <div class="weui-cell__hd">
                            <input type="checkbox" class="weui-check" name="CBWeek" id="@id" checked="checked" onchange="CheckWeek()" />
                            <i class="weui-icon-checked"></i>
                        </div>
                        <div class="weui-cell__bd">
                            <p>@($"周{weeks[i]}")</p>
                        </div>
                    </label>
                </div>
            }
        </div>

    </div>
    <div class="weui-cells weui-cells_form">
        @if (isDelay)
        {
            for (int i = 0; i < Model.Items.Count; i++)
            {
                <div id="@("DivParent"+i)">
                    <div class="weui-cell">
                        <div class="weui-cell__hd"><label class="weui-label">@Model.Items[i].RoomTypeName</label></div>
                        <div class="weui-cell__bd">
                            <input type="hidden" asp-for="Items[i].RoomTypeId" />
                            <input type="hidden" asp-for="Items[i].RoomTypeName" />
                            <input type="hidden" asp-for="Items[i].P0" />
                            <input type="hidden" asp-for="Items[i].P1" />
                            <input type="hidden" asp-for="Items[i].P2" />
                            <input type="hidden" asp-for="Items[i].P3" />
                            <input type="hidden" asp-for="Items[i].P4" />
                            <input type="hidden" asp-for="Items[i].P5" />
                            <input type="hidden" asp-for="Items[i].P6" />
                            <input class="weui-input" type="number" pattern="[0-9]*" placeholder="请输入房价" name="TBPrice" id="@("TBPrice"+i)" onchange="SetPrice(@i)" onfocus="ShowDetails(@i)" />
                        </div>
                    </div>
                    <div id="@("DivRoomType"+i)" name="DivRoomType">
                        <div class="weui-cell" name="DivWeek0">
                            <div class="weui-cell__hd"><label class="weui-label" name="Label0">周日</label></div>
                            <div class="weui-cell__bd">
                                <input class="weui-input" type="number" readonly tabindex="-1" asp-for="Items[i].D0" />
                            </div>
                        </div>
                        <div class="weui-cell" name="DivWeek1">
                            <div class="weui-cell__hd"><label class="weui-label" name="Label1">周一</label></div>
                            <div class="weui-cell__bd">
                                <input class="weui-input" type="number" readonly tabindex="-1" asp-for="Items[i].D1" />
                            </div>
                        </div>
                        <div class="weui-cell" name="DivWeek2">
                            <div class="weui-cell__hd"><label class="weui-label" name="Label2">周二</label></div>
                            <div class="weui-cell__bd">
                                <input class="weui-input" type="number" readonly tabindex="-1" asp-for="Items[i].D2" />
                            </div>
                        </div>
                        <div class="weui-cell" name="DivWeek3">
                            <div class="weui-cell__hd"><label class="weui-label" name="Label3">周三</label></div>
                            <div class="weui-cell__bd">
                                <input class="weui-input" type="number" readonly tabindex="-1" asp-for="Items[i].D3" />
                            </div>
                        </div><div class="weui-cell" name="DivWeek4">
                            <div class="weui-cell__hd"><label class="weui-label" name="Label4">周四</label></div>
                            <div class="weui-cell__bd">
                                <input class="weui-input" type="number" readonly tabindex="-1" asp-for="Items[i].D4" />
                            </div>
                        </div><div class="weui-cell" name="DivWeek5">
                            <div class="weui-cell__hd"><label class="weui-label" name="Label5">周五</label></div>
                            <div class="weui-cell__bd">
                                <input class="weui-input" type="number" readonly tabindex="-1" asp-for="Items[i].D5" />
                            </div>
                        </div><div class="weui-cell" name="DivWeek6">
                            <div class="weui-cell__hd"><label class="weui-label" name="Label6">周六</label></div>
                            <div class="weui-cell__bd">
                                <input class="weui-input" type="number" readonly tabindex="-1" asp-for="Items[i].D6" />
                            </div>
                        </div>
                    </div>
                </div>
            }
        }
        else
        {
            for (int i = 0; i < Model.Items.Count; i++)
            {
                <div id="@("DivParent"+i)">
                    <div class="weui-cell">
                        <div class="weui-cell__hd"><label class="weui-label">@Model.Items[i].RoomTypeName</label></div>
                        <div class="weui-cell__bd">
                            <input type="hidden" asp-for="Items[i].RoomTypeId" />
                            <input type="hidden" asp-for="Items[i].RoomTypeName" />
                            <input type="hidden" asp-for="Items[i].D0" />
                            <input type="hidden" asp-for="Items[i].D1" />
                            <input type="hidden" asp-for="Items[i].D2" />
                            <input type="hidden" asp-for="Items[i].D3" />
                            <input type="hidden" asp-for="Items[i].D4" />
                            <input type="hidden" asp-for="Items[i].D5" />
                            <input type="hidden" asp-for="Items[i].D6" />
                            <input class="weui-input" type="number" pattern="[0-9]*" placeholder="请输入房价" name="TBPrice" id="@("TBPrice"+i)" onchange="SetPrice(@i)" onfocus="ShowDetails(@i)" />
                        </div>
                    </div>
                    <div id="@("DivRoomType"+i)" name="DivRoomType">
                        <div class="weui-cell" name="DivWeek0">
                            <div class="weui-cell__hd"><label class="weui-label" name="Label0">周日</label></div>
                            <div class="weui-cell__bd">
                                <input class="weui-input" type="number" readonly tabindex="-1" asp-for="Items[i].P0" />
                            </div>
                        </div>
                        <div class="weui-cell" name="DivWeek1">
                            <div class="weui-cell__hd"><label class="weui-label" name="Label1">周一</label></div>
                            <div class="weui-cell__bd">
                                <input class="weui-input" type="number" readonly tabindex="-1" asp-for="Items[i].P1" />
                            </div>
                        </div>
                        <div class="weui-cell" name="DivWeek2">
                            <div class="weui-cell__hd"><label class="weui-label" name="Label2">周二</label></div>
                            <div class="weui-cell__bd">
                                <input class="weui-input" type="number" readonly tabindex="-1" asp-for="Items[i].P2" />
                            </div>
                        </div>
                        <div class="weui-cell" name="DivWeek3">
                            <div class="weui-cell__hd"><label class="weui-label" name="Label3">周三</label></div>
                            <div class="weui-cell__bd">
                                <input class="weui-input" type="number" readonly tabindex="-1" asp-for="Items[i].P3" />
                            </div>
                        </div><div class="weui-cell" name="DivWeek4">
                            <div class="weui-cell__hd"><label class="weui-label" name="Label4">周四</label></div>
                            <div class="weui-cell__bd">
                                <input class="weui-input" type="number" readonly tabindex="-1" asp-for="Items[i].P4" />
                            </div>
                        </div><div class="weui-cell" name="DivWeek5">
                            <div class="weui-cell__hd"><label class="weui-label" name="Label5">周五</label></div>
                            <div class="weui-cell__bd">
                                <input class="weui-input" type="number" readonly tabindex="-1" asp-for="Items[i].P5" />
                            </div>
                        </div><div class="weui-cell" name="DivWeek6">
                            <div class="weui-cell__hd"><label class="weui-label" name="Label6">周六</label></div>
                            <div class="weui-cell__bd">
                                <input class="weui-input" type="number" readonly tabindex="-1" asp-for="Items[i].P6" />
                            </div>
                        </div>
                    </div>
                </div>
            }
        }
    </div>
    <wx-buttons asp-link-text-1="保存" asp-link-type-1=EButtonType.Primary
                asp-link-text-2="删除" asp-fun-2="Delete"
                asp-link-text-3="返回" asp-page-3="./EditPrice" />

</form>
@section Scripts {
    @{
        await Html.RenderPartialAsync("_ValidationScriptsPartial");
    }
    <script>

        var isDelay = "@(isDelay ? "1" : "0")";
        function CheckWeek(id) {
            if (id == 0) {
                for (var v = 0; v < 7; v++) {
                    $("#CB" + v).prop("checked", !$("#CB" + v).prop("checked"));
                };
            }
            else if (id == 1) {
                for (var v = 0; v < 7; v++) {
                    $("#CB" + v).prop("checked", true);
                };
                $("[name='DivRoomType']").show();
            }


            var canEdit = false;
            for (var i = 0; i < 7; i++) {
                if ($("#CB" + i).prop("checked")) {
                    $(`[name="DivWeek${i}"]`).show();
                    canEdit = true;
                }
                else {
                    $(`[name="DivWeek${i}"]`).hide();
                }
            }
            if (canEdit) {
                $("[name='TBPrice']").removeAttr("disabled");
                $("[name='TBPrice']").val(null);
                $("[name='TBPrice']").attr("placeholder", "请输入房价");
            }
            else {
                $("[name='TBPrice']").attr("disabled", "");
                $("[name='TBPrice']").attr("placeholder", "无法输入");
            }

        }

        function Delete() {
            ShowConfirm("您确定要删除吗？").on(function (yn) {
                if (yn) {
                    $("#FormPost").attr("action", '@Url.Page("./EditPriceDetail")' + "?handler=delete");
                    $("#FormPost").submit();
                }
            });

        }


        function ShowDetails(id) {
            $("#DivRoomType" + id).show();
            $("#DivParent" + id).siblings().find("[name='DivRoomType']").hide();
            $("#DivTop").hide();
            $("#DivShow").show();
        }
        function SetPrice(rowNo) {
            $("[name='DivResult'").remove();
            var value = $(`#TBPrice${rowNo}`).val();
            $(`#TBPrice${rowNo}`).val(null);
            for (var i = 0; i < 7; i++) {

                if ($(`#CB${i}`).prop("checked")) {
                    if (isDelay == "1")
                        $(`#Items_${rowNo}__D${i}`).val(value * 1);
                    else
                        $(`#Items_${rowNo}__P${i}`).val(value * 1);

                }
            }
        }
        function ShowTop() {
            $("#DivShow").hide();
            $("#DivTop").show();
        }

    </script>
}
